package com.yinhai.activity;


import com.lz.util.Utils;
import com.yinhai.constant.SoundConstant;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class NoteManage {
	private static int msgId = 2;
	private static int surpriseId = 1;
	
    /**
     * 消息通知
     * */
    @SuppressWarnings("deprecation")
	public static synchronized void sendNotificationForPush(NotificationManager nm, Context context,String Istype,String title , String content,String url) {
    	
    	Intent intent = new Intent();        
		intent.setAction("android.intent.action.VIEW");    
		Uri content_url = Uri.parse(url);   
		intent.setData(content_url);  
		PendingIntent pendingIntent= null;
		if(Istype.equals("0")){
			 pendingIntent= null;
		}else{
			 pendingIntent = PendingIntent.getActivity(context, 2, intent, PendingIntent.FLAG_UPDATE_CURRENT);
		}
    	
    	Notification notification = new Notification();
    	notification.icon=R.drawable.dial_incomming_normal;
    	notification.tickerText=title;
    	//String sound=Utils.getSound(context);
    	if(Utils.getSound(context)) {
    		notification.defaults = Notification.DEFAULT_SOUND;
    	} else if(!Utils.getSound(context)) {
    		notification.defaults = Notification.DEFAULT_VIBRATE;
    	} else {
    		notification.defaults = Notification.DEFAULT_ALL;
    	}
    	notification.flags=Notification.FLAG_AUTO_CANCEL;
    	notification.when=System.currentTimeMillis();
    	notification.setLatestEventInfo(context, title, content, pendingIntent);
    	
    	nm.notify(0, notification);
    }
    
    
    /**
     * 公告
     * */
    @SuppressWarnings("deprecation")
	public static synchronized void sendNotificationForMsg(NotificationManager nm, Context context) {
    	Intent intent = new Intent(context, NewsContentActivity.class);
		intent.putExtra("action", 1);
	//	intent.setAction(Intent.ACTION_MAIN);
		//intent.addCategory(Intent.CATEGORY_LAUNCHER);
		//intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED|Intent.FLAG_ACTIVITY_NO_USER_ACTION);
		
    	PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    	Notification notification = new Notification();
    	notification.icon=R.drawable.dial_incomming_normal;
    	notification.tickerText="你有新的公告！";
    	//String sound=Utils.getSound(context);
    	if(Utils.getSound(context)) {
    		notification.defaults = Notification.DEFAULT_SOUND;
    	} else if(!Utils.getSound(context)) {
    		notification.defaults = Notification.DEFAULT_VIBRATE;
    	} else {
    		notification.defaults = Notification.DEFAULT_ALL;
    	}
    	notification.flags=Notification.FLAG_AUTO_CANCEL;
    	notification.when=System.currentTimeMillis();
    	notification.setLatestEventInfo(context, "你有新的公告", "快去看看！", pendingIntent);
    	
    	nm.notify(surpriseId, notification);
    }
    
}
